﻿@using DeliveryPlus.Web.DAL
@using DeliveryPlus.Web.DAL.Entities
@model System.Collections.Generic.List<DeliveryPlus.Web.DAL.Entities.Dishe>

@{
    var cafe = (Cafe)ViewBag.cafe;
    ViewBag.Title = @cafe.Title + " | Заведения";
    Layout = "../Shared/Layout.cshtml";
    var allTypes = cafe.Dishes.Select(d => d.TypeId).ToArray();
    var types = new DeliveryPlusDataContext().DishTypes.Where(dt => allTypes.Contains(dt.Id));
    long typeParam = ViewBag.type;
}

<div id="page-dishes" class="page">
    <div class="page-title">
        <img src="~/Content/images/cafe/title.png" />
    </div>
    <div class="row" id="first-row">
        <div class="left">
            <ul>
                <li><a href="/cafe">Заведения</a></li>
                <li class="active"><a href="/cafe/@cafe.Id/dishes">@cafe.Title</a></li>
            </ul>
            <img src="~/Content/images/dishes/sep-small.png" />
        </div>
        <div class="separator">
        </div>
        <div class="right">
            <div class="title">
                @cafe.Title
            </div>
            <img src="~/Content/images/dishes/sep-large.png" />
        </div>
    </div>
    <div class="row" id="second-row">
        <div class="left">
            <div class="wrap">
                @foreach (var group in types.GroupBy(t => t.GroupName))
                {
                    <div class="types-group">
                        @if (!String.IsNullOrEmpty(group.Key))
                        {
                            <div class="group-title">
                                @group.Key
                            </div>
                        }
                        <ul class="type-filter">
                            @foreach (var type in group)
                            {
                                <li @(typeParam == type.Id ? "class=active":"")><a href="/cafe/@cafe.Id/dishes?type=@type.Id">@type.Title</a></li>    
                            }
                        </ul>
                    </div>
                }
                <p style="margin: 5px">
                    <a href="/cafe/@cafe.Id/dishes">Все блюда</a>
                </p>    
            </div>
            <img src="~/Content/images/dishes/sep-small.png" />
        </div>
        <div class="separator">
        </div>
        <div class="right">
            <div id="dishes">
                @if (Model.Count == 0)
                {
                    <div id="no-res">
                        К сожалению, данный тип блюд не представлен в меню заведения. Пожалуйста, посмотрите список <a href="/cafe/@cafe.Id/dishes">ВСЕХ БЛЮД</a> заведения.
                    </div>
                }
                else
                {
                    foreach (var dish in Model.Where(d => !d.Hidden))
                    {
                        <div class="dish">
                            <div class="dish-image" onclick="window.location.href='/dish/@dish.Id'">
                                @if (!String.IsNullOrEmpty(dish.Photo))
                                {
                                    <img class="lazy" data-original="/Files/Dish/@dish.Photo" alt="@dish.Title, @cafe.Title, Хабаровск"/>
                                }
                            </div>
                            <div class="dish-order" title="Добавить в заказ" onclick="orderDish(@dish.Id);"></div>
                            <div class="dish-title">
                                <a href="/dish/@dish.Id">
                                    @if (!String.IsNullOrEmpty(dish.Energy))
                                    {
                                        <span style="color: #f3f3f3">(@dish.Energy)</span>     
                                    }
                                    @dish.Title
                                    @if (!String.IsNullOrEmpty(dish.Weight))
                                    {
                                        <br/>
                                        <span style="color: #f3f3f3">(@dish.Weight грамм)</span>         
                                    }
                                </a>
                            </div>
                            <div class="dish-price">
                                @String.Format("{0:c}",dish.Price)
                            </div>
                        </div>
                    }
                }
            </div>
            <img src="~/Content/images/dishes/sep-large.png" />
        </div>
    </div>
    <div class="row" id="third-row">
        <div class="left">
            <div id="address">
                @Html.Raw((cafe.Address ?? "").Replace("\r","<br/>").Replace("\n","<br/>"))
            </div>
            <img src="~/Content/images/dishes/sep-small.png" />
        </div>
        <div class="separator">
        </div>
        <div class="right">
            <div id="desc">
                @Html.Raw(cafe.Description)    
            </div>
            <img src="~/Content/images/dishes/sep-large.png" />
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $(window).resize(function () {
            // Second
            var left = $("#second-row .left .wrap").height();
            var right = $("#second-row .right #dishes").height();
            if (left >= right) {
                $("#second-row .separator").height(left);
                $("#dishes").height(left);
            } else {
                $("#second-row .separator").height(right);
                $("#second-row .left .wrap").height(right);
            }
            
            // Third
            left = $("#third-row .left #address").height();
            right = $("#third-row .right #desc").height();
            if (left >= right) {
                $("#third-row .separator").height(left);
                $("#desc").height(left);
            } else {
                $("#third-row .left #address").height(right);
                $("#third-row .separator").height(right);
            }
        }).resize();
    });
</script>
